#ifndef SIMUBOARD_THEME_HPP
#define SIMUBOARD_THEME_HPP

#include <FL/Fl.H>
#include <cstdint>

namespace GUI
{
    struct Theme
    {
        Fl_Color window_bg;
        Fl_Color card_bg;
        Fl_Color text_primary;
        Fl_Color text_secondary;
        Fl_Color accent;
    };

    // 基础亮色主题
    inline Theme light_theme()
    {
        return Theme{
            fl_rgb_color(0xEB, 0xEB, 0xEB), // window_bg
            fl_rgb_color(0xFF, 0xFF, 0xFF), // card_bg
            FL_BLACK, // text_primary
            fl_rgb_color(0x66, 0x66, 0x66), // text_secondary
            fl_rgb_color(0x2D, 0x9C, 0xDB) // accent
        };
    }

    // 基础暗色主题
    inline Theme dark_theme()
    {
        return Theme{
            fl_rgb_color(0x1E, 0x1F, 0x22),
            fl_rgb_color(0x28, 0x2A, 0x2E),
            fl_rgb_color(0xEE, 0xEE, 0xEE),
            fl_rgb_color(0xAA, 0xAA, 0xAA),
            fl_rgb_color(0x4C, 0xAF, 0x50)
        };
    }

    // 根据小时返回主题：白天亮色、夜晚偏暗，清晨/傍晚过渡
    inline Theme theme_for_hour(uint8_t hour)
    {
        if (hour >= 7 && hour <= 18)
        {
            return light_theme();
        }
        // 过渡：16~19 逐渐变暗，5~7 逐渐变亮（简化：使用两档即可）
        if ((hour > 16 && hour <= 19) || (hour >= 5 && hour < 7))
        {
            Theme t = light_theme();
            // 稍微降低亮度
            t.window_bg = fl_rgb_color(0xD8, 0xD8, 0xD8);
            t.card_bg = fl_rgb_color(0xF6, 0xF6, 0xF6);
            t.text_primary = fl_rgb_color(0x22, 0x22, 0x22);
            t.text_secondary = fl_rgb_color(0x55, 0x55, 0x55);
            t.accent = fl_rgb_color(0x26, 0x85, 0xBA);
            return t;
        }
        return dark_theme();
    }

    // 全局当前主题（简化，无同步）
    inline Theme& mutable_current_theme()
    {
        static Theme g = light_theme();
        return g;
    }

    inline void set_current_theme(const Theme& t)
    {
        mutable_current_theme() = t;
    }

    inline const Theme& current_theme()
    {
        return mutable_current_theme();
    }
} // namespace GUI

#endif // SIMUBOARD_THEME_HPP
